package com.yikaiye.android.yikaiye.ui.fragment;

import android.util.Log;

import androidx.fragment.app.Fragment;

import com.yikaiye.android.yikaiye.R;
import com.yikaiye.android.yikaiye.base.BaseFragment;
import com.yikaiye.android.yikaiye.base.BaseViewModel;
import com.yikaiye.android.yikaiye.config.Constant;
import com.yikaiye.android.yikaiye.databinding.FragmentOrderBinding;
import com.yikaiye.android.yikaiye.ui.adapter.ViewPagerAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * 订单ø
 */
public class OrderFragment extends BaseFragment<FragmentOrderBinding, BaseViewModel> {

    private final List<Fragment> fragments = new ArrayList<>();

    @Override
    public void lazyLoadData() {
        List<String> titles = new ArrayList<>();
        titles.add(mContext.getString(R.string.all_text));
        titles.add(mContext.getString(R.string.wait_payment));
        titles.add(mContext.getString(R.string.already_pay));
        titles.add(mContext.getString(R.string.already_cancel));
        for (int i = 0; i < titles.size(); i++) {
            fragments.add(OrderStatusFragment.newInstance(i == 0 ? null : String.valueOf(i - 1)));
        }
        ViewPagerAdapter adapter = new ViewPagerAdapter(getChildFragmentManager(), 0, titles, fragments);
        binding.viewPager.setAdapter(adapter);
        binding.tabLayout.setViewPager(binding.viewPager);
        binding.viewPager.setOffscreenPageLimit(4);
    }

    @Override
    protected BaseViewModel bindModel() {
        return getViewModel(this, BaseViewModel.class);
    }

    @Override
    protected void initInject() {
        getFragmentComponent().inject(this);
    }

    @Override
    public void initData() {

    }

    @Override
    public void onResume() {
        super.onResume();
        Log.e("onResume", "OrderFragment-onResume=====" + Constant.currentPosition);
        if (Constant.isFromPay) {
            binding.viewPager.setCurrentItem(Constant.currentPosition);
            Constant.isFromPay = false;
        }
    }
}
